package org.answer.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.answer.dao.AddressDao;
import org.answer.entity.PageResult;
import org.answer.entity.QueryPageBean;
import org.answer.pojo.AddressMap;
import org.answer.service.AddressService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AddressServiceImpl implements AddressService {

    @Autowired
    private AddressDao addressDao;

    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<AddressMap> addressMaps = addressDao.findByCondition(queryPageBean.getQueryString());
        return new PageResult(addressMaps.getTotal(),addressMaps.getResult());
    }

    @Override
    public List<AddressMap> findAll() {
        return addressDao.findAll();
    }

    @Override
    public void add(AddressMap addressMap) {
        addressDao.add(addressMap);
    }

    @Override
    public void edit(AddressMap addressMap) {
        addressDao.edit(addressMap);
    }

    @Override
    public void delete(Integer id) {
        addressDao.deleteById(id);
    }

    @Override
    public AddressMap findById(Integer id) {
        return addressDao.findById(id);
    }
}
